package luanluan.control.managers 
{
	import flash.utils.Dictionary;
	import luanluan.control.application.ObjectPool;
	import luanluan.control.dlg.BasicDlg;
	/**
	 * 对话框管理
	 * @author luanluan
	 */
	public class DlgManager 
	{
		private var _dlgDic:Dictionary;
		
		/**
		 * 显示对话框
		 * @param	dlgClass	对话框类
		 * @param	onlyOne		是否只允许显示一个对话框
		 */
		public function showDlg(dlgClass:Class , onlyOne:Boolean = false , ...arg):void
		{
			var dlg:BasicDlg;
			if (onlyOne)
			{
				if (!_dlgDic[dlgClass])
					_dlgDic[dlgClass] = ObjectPool.instance.getObject(dlgClass);
				dlg = _dlgDic[dlgClass];
			}
			else
			{
				dlg = ObjectPool.instance.getObject(dlgClass);
			}
			dlg.show.apply(null , arg);
		}
		
		public function DlgManager(single:Single) 
		{
			if ( !single )
				throw(new Error( "请使用静态getter获取单例引用" ) );
			_dlgDic = new Dictionary();
		}
		
		private static var _instance:DlgManager = null;
		public static function get instance():DlgManager 
		{
			if (_instance == null)
				_instance = new DlgManager(new Single());
			return _instance;
		}
		
	}

}
class Single{}